package cn.graydove.bot.core;


import cn.graydove.bot.mirai.Client;
import net.mamoe.mirai.event.Event;

import java.util.ArrayList;
import java.util.List;

public class ProcessorManager {

    private List<Function> functions = new ArrayList<>();

    private List<Processor> processors = new ArrayList<>();

    public void register(Function function) {
        functions.add(function);
    }

    public void registerProcessor(Processor processor) {
        processors.add(processor);
    }

    public void handle(Client client) {
        String content = client.getMessage().contentToString();
        for (Function function: functions) {
            if (function.match(content)) {
                function.invoke(client);
                return;
            }
        }
    }

    public void process(Event event) {
        for (Processor processor : processors) {
            if (processor.accept(event)) {
                processor.process(event);
                break;
            }
        }
    }
}
